package com.bupt.smart.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.bupt.smart.smart.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wwl on 2016/3/29.
 */
public class ServiceFragment extends Fragment {
    /*public ListView lv;
    SimpleAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adapter = new SimpleAdapter(this.getActivity(),getData(),R.layout.market_list,
                new String[]{"imag","service","img"},//设定服务类型的string
                new int[]{R.id.imag,R.id.service,R.id.img});

    }

    //获取商家信息(连接数据库)
    public static List<Map<String,Object>> getData() {
        ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();*//*在数组中存放数据*//*

        for (int i = 0; i < 6; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("img", R.mipmap.btn_icon_repair);
            map.put("service", "维修服务");
            map.put("img", R.mipmap.btn_icon_arrow);
            listItem.add(map);
        }
        return listItem;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.service_fragment, null);
        lv = (MyListView)v.findViewById(R.id.lv);*//*定义一个动态数组*//*

        return v;
    }
    }*/
    private String [] info_service={"维修服务","家政服务","快递服务","装修服务","医疗服务","洗车服务"};
    //定义一个ArrayList数组，每一条数据对应一种服务
    private ArrayList <Map <String,Object> >  mInfos= new ArrayList <Map <String,Object> > ();
    //定义一个ListView
    private ListView mListView;
    SimpleAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //添加数据
        int[] pics = {
                R.mipmap.btn_icon_repair,R.mipmap.btn_icon_jiazheng,R.mipmap.btn_icon_kuaidi,
                R.mipmap.btn_icon_zhuangxiu,R.mipmap.btn_icon_yiliao,R.mipmap.btn_icon_xiche
        };
        for(int i=0;i <info_service.length;i++){
            Map <String,Object>  item = new HashMap <String,Object> ();
            item.put("img", pics[i]);
            item.put("service", info_service[i]);
            item.put("img2", R.mipmap.btn_icon_arrow);
            mInfos.add(item);
        }
        //定义一个SimpleAdapter
        adapter = new SimpleAdapter(this.getActivity(), mInfos, R.layout.service_list, new String[]{"img","service","imag2"},new int[]{R.id.service_fragment_img,R.id.service_fragment_service,R.id.service_fragment_imag2});

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.service_fragment, null);
        mListView = (ListView) v.findViewById(R.id.servicelist);
        mListView.setAdapter(adapter);
        return v;
    }


}




